<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 网站用户 iframe 框</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-useradmin" id="layuiadmin-form-useradmin" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">发帖人</label>
        <div class="layui-input-inline">
            <input type="text" th:value="${topic != null}?${topic.nickname}:${session.Admin.name}" id="nickname"
                   name="nickname" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">头像</label>
        <div class="layui-input-inline">
            <input lay-verify="required" id="avatarUrl" name="avatarUrl" placeholder="图片地址"
                   th:value="${topic != null}?${topic.avatarUrl}:${session.admin.img}" class="layui-input">
        </div>
        <div class="layui-input-inline layui-btn-container" style="width: auto;">
            <button class="layui-btn layui-btn-primary" id="showAva">查看图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发帖时间</label>
        <div class="layui-input-inline">
            <input lay-verify="required" id="time" name="time"  autocomplete="off"
                   placeholder="发帖时间" th:value="${topic != null}?${topic.createtime}" class="layui-input">
        </div>

    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">话题图片</label>
        <div class="layui-input-inline">
            <input name="img" lay-verify="required" id="img" placeholder="图片地址"
                   autocomplete="off" th:value="${topic != null}?${topic.img}" class="layui-input">
        </div>
        <div class="layui-input-inline layui-btn-container" style="width: auto;">
            <button type="button" class="layui-btn layui-btn-primary" id="upload">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>
            <button class="layui-btn layui-btn-primary" id="showImg">查看图片
            </button>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">话题内容</label>
        <div class="layui-input-block" style="margin-right: 50px;">
        <textarea class="layui-textarea" id="content" name="content" lay-verify="content_desc" style="display: none">
            [[${topic != null}?${topic.content}]]
        </textarea>
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="addTopic" id="addTopic" value="确认">
    </div>
</div>

<script src="../../../layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '../../../layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'layer','laydate', 'layedit', 'upload'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,upload = layui.upload ;


        laydate.render({
            elem : '#time',
            type : 'datetime'
        });
        //构建一个默认的编辑器
        layedit.set({
            uploadImage: {
                url: '/uploadByEdit' //接口url
                ,type: 'post' //默认post
            }
        });
        var index = layedit.build('content', {
            height: 180 //设置编辑器高度
        });
        form.verify({
            content_desc: function(value){
                layedit.sync(index);
            }
        });
        //console.log(layedit.getContent(index))
        console.log($("#content").val());
        var uploadInst = upload.render({
            elem: '#upload' //绑定元素
            , url: '/upload' //上传接口
            , done: function (res) {
                //上传完毕回调
                if (res.code == 200) {
                    $("#img").val(res.msg);
                    layer.msg('图片上传成功',
                        {
                            icon: 1,
                            time: 800
                        });
                } else {
                    layer.msg('图片上传失败');
                }
            }
            , error: function () {
                //请求异常回调
            }
        });
        $('#showAva').on('click', function () {
            layer.photos(
                {photos: {title: "查看头像", data: [{src: $("#avatarUrl").val()}]}, shade: .01, closeBtn: 1, anim: 5}
            )
            return false;
        });
        $('#showImg').on('click', function () {
            layer.photos(
                {photos: {title: "查看图片", data: [{src: $("#img").val()}]}, shade: .01, closeBtn: 1, anim: 5}
            )
            return false;
        });
    })
</script>
</body>
</html>